<script type="text/javascript">
/* Page init setting for User */
var initUrl = "<?= Zend_Registry::get('baseUrl')?>/admin/log/query";
var initParam = "currentpage=1";
var columnName = new Array("time", "username", "module", "project", "level", "message");
var operate = "";
var currentPage = "1";

$(document).ready(function() {
	fillData(initUrl, initParam, columnName, operate, currentPage);
});

/* Go to Edit */
function goEdit() {
	
}

/* Search data */
function doSearch(isSearch, currentPage) {
	if ($.trim($("#starttime").val()) != '') {
    	if (! isDateTime("starttime")) {
    		$("#msg").text("<?= $this->translate('message.common.validate.datetime')?>");
    		return false;
    	}
	}
	if ($.trim($("#endtime").val()) != '') {
    	if (! isDateTime("endtime")) {
    		$("#msg").text("<?= $this->translate('message.common.validate.datetime')?>");
    		return false;
    	}
	}
	if (isSearch) {
		$("#cacheDiv").removeData("cacheData");
		var cacheArray = new Array();
		cacheArray['starttime'] = $.trim($("#starttime").val());
		cacheArray['endtime'] = $.trim($("#endtime").val());
		cacheArray['username'] = $.trim($("#username").val());
		cacheArray['module'] = $.trim($("#module").val());
		cacheArray['project'] = $.trim($("#project").val());
		cacheArray['level'] = $.trim($("#level").val());
		cacheArray['message'] = $.trim($("#message").val());
		$("#cacheDiv").data("cacheData", cacheArray);
	}
	var cacheData = $("#cacheDiv").data("cacheData");
	if (typeof(cacheData) == "undefined")
		var param = "currentpage=" + currentPage;
	else
		var param = "currentpage=" + currentPage +
				"&starttime=" + cacheData['starttime'] + 
		    	"&endtime=" + cacheData['endtime'] + 
		    	"&username=" + cacheData['username'] + 
		    	"&module=" + cacheData['module'] +
		    	"&project=" + cacheData['project'] +
		    	"&level=" + cacheData['level'] + 
		    	"&message=" + cacheData['message'];
	fillData(initUrl, param, columnName, operate, currentPage);
	$("#msg").text("<?= $this->translate('tip.common.action')?>");
}

</script>
<table class="table-action">
<thead>
<tr>
	<a name="top"></a>
    <td colspan="5">
        <?= $this->translate('common.page.panel')?>:&nbsp;&nbsp;
    	<label id="hideShow" />
    </td>
</tr>
</thead>
<tbody>
<tr>
	<td width="14%"><?= $this->translate('column.logging.starttime')?>:</td>
	<td width="36%"><input type="text" id="starttime" value="<?= date('Y-m-d H:i:s', time() - 3600 * 24 * 30)?>" class="short" onclick="calendar(this, true)" /></td>
	<td width="15%"><?= $this->translate('column.logging.endtime')?>:</td>
	<td width="25%" align="right"><input type="text" id="endtime" value="<?= date('Y-m-d H:i:s')?>" class="short" onclick="calendar(this, true)" /></td>
	<td width="10%"></td>
</tr>
<tr>
	<td><?= $this->translate('column.logging.username')?>:</td>
	<td><input type="text" id="username" maxlength="30" class="short" /></td>
	<td><?= $this->translate('column.logging.module')?>:</td>
	<td align="right">
	<select id="module" class="short">
		<option value=""></option>
		<?php 
		    echo '<option value="' , Logging::MODULE_SYSTEM , '">' , Logging::MODULE_SYSTEM , '</option>';
		    echo '<option value="' , Logging::MODULE_ADMIN , '">' , Logging::MODULE_ADMIN , '</option>';
		    echo '<option value="' , Logging::MODULE_DASHBOARD , '">' , Logging::MODULE_DASHBOARD , '</option>';
		    echo '<option value="' , Logging::MODULE_NOTICE , '">' , Logging::MODULE_NOTICE , '</option>';
		    echo '<option value="' , Logging::MODULE_MINUTES , '">' , Logging::MODULE_MINUTES , '</option>';
		    echo '<option value="' , Logging::MODULE_KNOWLEDGE , '">' , Logging::MODULE_KNOWLEDGE , '</option>';
		    echo '<option value="' , Logging::MODULE_PROJECT , '">' , Logging::MODULE_PROJECT , '</option>';
		    echo '<option value="' , Logging::MODULE_PROPOSAL , '">' , Logging::MODULE_PROPOSAL , '</option>';
		    echo '<option value="' , Logging::MODULE_USERSTORY , '">' , Logging::MODULE_USERSTORY , '</option>';
		    echo '<option value="' , Logging::MODULE_SPEC , '">' , Logging::MODULE_SPEC , '</option>';
		    echo '<option value="' , Logging::MODULE_TESTCASE , '">' , Logging::MODULE_TESTCASE , '</option>';
		    echo '<option value="' , Logging::MODULE_EXECUTION , '">' , Logging::MODULE_EXECUTION , '</option>';
		    echo '<option value="' , Logging::MODULE_DEFECT , '">' , Logging::MODULE_DEFECT , '</option>';
		?>
	</select></td>
	<td></td>
</tr>
<tr>
	<td><?= $this->translate('column.logging.project')?>:</td>
	<td><select id="project" class="short">
		<option value=""></option>
		<option value="System">System</option>
	<?php 
	    foreach ($this->project as $project) {
            echo '<option value="' , $project['projname'] , '">' , $project['projname'] , '</option>';
		}
	?></select>
	</td>
	<td><?= $this->translate('column.logging.level')?>:</td>
	<td align="right"><select id="level" class="short">
		<option value=""></option>
	<?php 
	    echo '<option value="' , Logging::LEVEL_INFO , '">' , Logging::LEVEL_INFO , '</option>';
	    echo '<option value="' , Logging::LEVEL_WARN , '">' , Logging::LEVEL_WARN , '</option>';
	    echo '<option value="' , Logging::LEVEL_ERROR , '">' , Logging::LEVEL_ERROR , '</option>';
	?>
	</select></td>
	<td></td>
</tr>
<tr>
	<td><?= $this->translate('column.logging.message')?>:</td>
	<td colspan="3"><input type="text" id="message" class="long" /></td>
	<td></td>
</tr>
</tbody>
<tfoot>
<tr>
	<td><?= $this->translate('common.page.operate')?>:</td>
	<td>
		<input type="button" onclick="doSearch(true,1)" value="<?= $this->translate('common.button.search')?>" />&nbsp;&nbsp;
		<input type="button" id="reset" value="<?= $this->translate('common.button.reset')?>" />
	</td>
	<td colspan="3">
		<span id="msg" class="message"><?= $this->translate('tip.common.action')?></span>
		<span id="loading" class="loading"><img src="<?= Zend_Registry::get('baseDir')?>/Common/Image/loading.gif" /></span>
	</td>
</tr>
</tfoot>
</table>

<br />
<table class="table-data" id="dataTable">
<thead>
<tr>
    <th width="21%" class="id"><?= $this->translate('column.logging.time')?></th>
    <th width="13%"><?= $this->translate('column.logging.username')?></th>
    <th width="11%"><?= $this->translate('column.logging.module')?></th>
    <th width="14%"><?= $this->translate('column.logging.project')?></th>
    <th width="9%"><?= $this->translate('column.logging.level')?></th>
    <th width="32%"><?= $this->translate('column.logging.message')?></th>
</tr>
</thead>
<tbody id="dataPanel"></tbody>
<tfoot id="footer"></tfoot>
</table>